﻿package game.exchangeddata 
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.xml.XMLNode;
	import game.events.EventData;
	/**
	 * ...
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)
	 */
	public class LanguageInfo extends EventDispatcher
	{
		private var arrID:Array;
		private var arrLangG:Array;
		private var arrLangK:Array;
		private var arrLangE:Array;
		private var arrLangB:Array;
		
		private var arrLangV:Array;
		private var arrLangJ:Array;
		private var arrLangT:Array;
		private var arrLangM:Array;
		private var arrLangI:Array;
		
		public var hashTable:HashTable;
		
		
		public function LanguageInfo() 
		{
			this.arrID = new Array();
			this.arrLangG = new Array();
			this.arrLangB = new Array();
			this.arrLangT = new Array();
			this.arrLangK = new Array();
			this.arrLangJ = new Array();
			this.arrLangV = new Array();
			this.arrLangM = new Array();
			this.arrLangE = new Array();
			//this.arrLangI = new Array();
			
		}
		/**
		 * @author	Bamboo
		 * @param	xmlNode
		 * @param	lang
		 */
		public function updateInfo(xmlNode:XMLNode, lang:String):void {
			if (xmlNode == null)
				return;
			var lengthXML:Number = xmlNode.childNodes.length;
			
			var id, langG, langB,langT, langK , langJ, langV, langM, langE:String;
			
			for (var i:Number = 0; i<lengthXML; i++) {
				id = xmlNode.childNodes[i].attributes.id;
				this.arrID.push(id);
				langG = xmlNode.childNodes[i].attributes["langG"];
				this.arrLangG.push(langG);
				
				langB = xmlNode.childNodes[i].attributes["langB"];
				this.arrLangB.push(langB);
				
				langT = xmlNode.childNodes[i].attributes["langT"];
				this.arrLangT.push(langT);
				
				langK = xmlNode.childNodes[i].attributes["langK"];
				this.arrLangK.push(langK);
				
				langJ = xmlNode.childNodes[i].attributes["langJ"];
				this.arrLangJ.push(langJ);
				
				langV = xmlNode.childNodes[i].attributes["langV"];
				this.arrLangV.push(langV);
				
				langM= xmlNode.childNodes[i].attributes["langM"];
				this.arrLangM.push(langM);
				
				langE = xmlNode.childNodes[i].attributes["langE"];
				this.arrLangE.push(langE);
				}// end for
			
			
			if (lang == "G") {
				hashTable = new HashTable(arrID, arrLangG);
			} else if (lang == "B") {
				hashTable = new HashTable(arrID, arrLangB);
			} else if (lang == "T") {
				hashTable = new HashTable(arrID, arrLangT);
			} else if (lang == "K") {
				hashTable = new HashTable(arrID, arrLangK);
			}else if (lang == "J") {
				hashTable = new HashTable(arrID, arrLangJ);
			}else if (lang == "V") {
				hashTable = new HashTable(arrID, arrLangV);
			}else if (lang == "M") {
				hashTable = new HashTable(arrID, arrLangM);
			}else if (lang == "E") {
				hashTable = new HashTable(arrID, arrLangE);
			}
			
			dispatchEvent(new Event(EventData.HASHTABLE_COMPLETE));
		}
		
		public function updateLangInfo(id:Array, info:Array):void {
			hashTable = new HashTable(id, info);
			dispatchEvent(new Event(EventData.HASHTABLE_COMPLETE));
		}
		
	}

}